﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Face.Web.VideoPage
{
    public partial class MyVideosManage : System.Web.UI.Page
    {
        private static IBLL.IVideo bllVideo = BLLFactory.DataAccess.GetVideo();
        private static IBLL.IAlbum bllAlbum = BLLFactory.DataAccess.GetAlbum();
        public int ThisVideoID;
        public int ThisAlbumID;
        public string thisVideoName = "新闻联播";
        public string thisVideoUpdateTime = "1天前";
        public string thisAlbumName = "新闻联播";
        public string thisVideoAlbumUpdateTime = "1天前";
        public string thisAlbumCreateTime;
        public string thisAlbumDescription;
        public int thisAlbumVideoNum;
        public string thisAlbumPictureURL = "/img/视频信息图.jpg";
        public DataMode.video_album thisAlbum;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Request.QueryString["AlbumID"] != null)
            {
                int test;
                if (System.Int32.TryParse(Request.QueryString["AlbumID"], out test))
                {
                    ThisAlbumID = test;
                }
            }
            if (ThisAlbumID > 0)
            {
                thisAlbum = bllAlbum.GetThisAlbumInfoByAlbumID(ThisAlbumID);
                thisAlbumName = thisAlbum.album_name;
                thisAlbumCreateTime = thisAlbum.album_create_time.ToString();;
                thisAlbumPictureURL = thisAlbum.album_path;

            }
            if (!IsPostBack)
            {
                bindData();
            }
        }


        private void bindData()
        {
            //调用业务层
            Video_List.DataSource = bllAlbum.GetVideosByAlbumID(ThisAlbumID);
            Video_List.DataBind();
        }

        protected void rpt_Video_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "btn_DeleteVideo")
            {
                bllAlbum.DeleteAlbum(System.Int32.Parse(e.CommandArgument.ToString()));
                bindData();
            }
            if (e.CommandName == "btn_RenameOK")
            {
                string kindID = e.CommandArgument.ToString().Split(',')[0];
                int itemIndex = Convert.ToInt32(e.CommandArgument.ToString().Split(',')[1]);
                System.Web.UI.HtmlControls.HtmlInputText inputText = this.Video_List.Items[itemIndex].FindControl("text_Rename") as System.Web.UI.HtmlControls.HtmlInputText;
                bllVideo.RenameVideoByVideoID(System.Int32.Parse(kindID), inputText.Value);
                bindData();
            }
        }

        protected void btn_logout(object sender, EventArgs e)
        {
            Session.Remove("user");
            Response.Redirect("/login_and_signup/login.aspx");
        }
    }
}